import matplotlib.pyplot as plt

plt.rcParams['font.sans-serif'] = ['SimSun']  # 指定默认字体为新宋体。
plt.rcParams['axes.unicode_minus'] = False  # 解决保存图像时 负号'-' 显示为方块和报错的问题。

# 数据准备
x = ['苹果', '蓝莓', '樱桃', '橘子']
y = [40, 100, 30, 55]
labels = ['苹果', '蓝莓', '_樱桃', '橘子']
colors = ['tab:red', 'tab:blue', 'tab:red', 'tab:orange']
edge_colors = ["green", "red", "black", "blue"]
tick_label = ['apple', 'blueberry', 'cherry', 'orange']
yerr = [(3, 4, 5, 2), (5, 6, 7, 8)]

fig = plt.figure()  # 创建画布

axes = fig.add_subplot(111)  # 创建子图

axes.bar(x,
         y,
         color=colors,
         edgecolor=edge_colors,
         linewidth=1,
         tick_label=tick_label,
         label=labels,
         align="center",
         yerr=yerr,
         ecolor="purple",
         fill=False,
         hatch='/',
         linestyle='-.')
axes.legend()

axes.set_title("水果价格")
axes.set_xlabel("水 果")
axes.set_ylabel("数 量")

plt.show()
